package com.zhg.javakc.modules.sale.controller;

import com.zhg.javakc.base.page.Page;
import com.zhg.javakc.modules.sale.Service.SaleService;
import com.zhg.javakc.modules.sale.entity.SaleEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/sale")
public class SaleController {

    @Autowired
    SaleService saleService;

    @RequestMapping("/query")
    public String query(SaleEntity entity, ModelMap model,
                        HttpServletRequest request, HttpServletResponse response) throws Exception {
        model.put("page", saleService.findAll(new Page<SaleEntity>(request, response), entity));
        model.put("entity", entity);
        return "sale/list";
    }

    @RequestMapping("/queryType")
    @ResponseBody
    public List<String> queryType() {
        List<String> type = saleService.findType();
        return type;
    }

    @RequestMapping("/queryGam")
    @ResponseBody
    public List<String> queryGam() {
        List<String> gam = saleService.findGam();
        return gam;
    }

    @RequestMapping("/querySize/{gamName}")
    @ResponseBody
    public Map querySize(@PathVariable String gamName) {
        Map size = saleService.findSize(gamName);
        return size;
    }

    @RequestMapping(value = "/add")
    public String add(ModelMap model) {
        model.put("roleList", saleService.findList(null));
        return "system/user/create";
    }

}
